"""
选择菜单

以脚本方式会自动弹出浏览器
"""
import time

from pywebio.output import *
from pywebio.input import *

put_markdown('## Hello there')
put_text("I hope you are having a great day! Here is our menu")

put_table([
    ['Food', 'Price'],
    ['Noodle', 10],
    ['Chicken and rice', 11],
])

# 不阻塞
with popup("Subscribe to the page"):
    put_text("Join other foodies!")

# 阻塞
food = select("Choose your favorite food", ['noodle', 'chicken and rice'])
put_text(f"You chose {food}. Please wait until it is served!")

put_processbar('bar')
for i in range(1, 11):
    set_processbar('bar', i / 10)
    time.sleep(0.1)

put_markdown("Here is your food! Enjoy!")

if food == 'noodle':
    food_img = 'noodle.jpeg'
else:
    food_img = 'chicken_and_rice.jpeg'

put_image(open(food_img, 'rb').read())

put_file(
    name=food_img,
    content=open(food_img, 'rb').read(),
    label="You can download the food here",
)
